package com.gopay.scheduler.shedulerx;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoaderListener;

import javax.servlet.ServletContextEvent;

/**
 * @author 19371
 * 对于cron，外部调用间不会有幂扽性影响的系统，优先关闭调度，再销毁ServletContextEvent
 */
public class SchedulerXContextLisenter extends ContextLoaderListener {
    @Override
    public void contextDestroyed(ServletContextEvent event) {
        if(SchedulerOperateFactory.getFactory().isSchedulerX()) {
            LOGGER.info("------->SchedulerX is closing, please waiting <-------");
            SchedulerOperateFactory.getFactory().shutdown();
            LOGGER.info("------->SchedulerX has been closed, now destroyed ths ServletContextEvent<-------");
        }
        super.contextDestroyed(event);
    }
     private final static Logger LOGGER = LoggerFactory.getLogger(SchedulerXContextLisenter.class);
}
